{template 'public/header'}
{template 'public/comhead'}
<link href="{$_W['siteroot']}addons/weisrc_dish/plugin/gritter/jquery.gritter.css" rel="stylesheet">
<script src="{$_W['siteroot']}addons/weisrc_dish/plugin/gritter/jquery.gritter.min.js"></script>
<link rel="stylesheet" href="{$_W['siteroot']}addons/weisrc_dish/public/web/css/back.css">
<link rel="stylesheet" href="{$_W['siteroot']}addons/weisrc_dish/public/web/css/style.css?v=1.2">
<script src="{$_W['siteroot']}addons/weisrc_dish/public/web/js/jquery.flot.js?v=2.1.4"></script>
<script src="{$_W['siteroot']}addons/weisrc_dish/public/web/js/echarts-all.js?v=2.1.4"></script>
<style>
    .clearfix .row{
        margin-left: -15px;
        margin-right: -15px;
    }
</style>

<ul class="nav nav-tabs">
    <li {if $operation == 'display' || empty($operation)}class="active"{/if}><a href="{php echo $this->createWebUrl('cost', array('op' => 'display', 'storeid' => $storeid))}">成本统计</a></li>
    <li {if $operation == 'list' || empty($operation)}class="active"{/if}><a href="{php echo $this->createWebUrl('cost', array('op' => 'list', 'storeid' => $storeid))}">成本管理</a></li>
    <li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('cost', array('op' => 'post', 'storeid' => $storeid))}">添加成本</a></li>
</ul>
{if  $operation == 'display'}
<div class="clearfix">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="border-color: #e7eaec;border-style: solid solid none;"><h5>按日期筛选</h5>
                </div>
                <div class="ibox-content">
                    <form action="" method="get" class="form-horizontal" role="form" id="list">
                        <input type="hidden" name="c" value="site">
                        <input type="hidden" name="a" value="entry">
                        <input type="hidden" name="m" value="weisrc_dish">
                        <input type="hidden" name="do" value="cost"/>
                        <input type="hidden" name="op" value="display"/>
                        <input type="hidden" name="storeid" value="{$storeid}"/>

                        <div class="form-group clearfix">
                            <label class="col-xs-12 col-sm-2 col-md-1 control-label">时间范围</label>

                            <div class="col-sm-7 col-lg-8 col-md-8 col-xs-12">
                                {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i:s',$starttime),'endtime'=>date('Y-m-d H:i:s', $endtime)), true);}
                                <input class="btn btn-sm btn-success" name="commit" type="submit" value="搜索">
                                <button class="btn btn-sm btn-success" name="out_put" value="output"><i
                                        class="fa fa-file"></i> 导出</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="border-color: #e7eaec;border-style: solid solid none;"><h4>{php echo date('Y-m-d',$starttime);}至{php echo date('Y-m-d',$endtime)}数据统计</h4></div>
                <div class="account-stat"
                     style="background-color: #ffffff;border-color: #e7eaec;border-style: solid solid none;border-width: 1px 0px;">
                    <div class="account-stat-btn">
                        <div class="col-12" style="width: 160px;">营业额
                            <span>{php echo sprintf('%.2f', $total_order_price);}{$setting['currency']}</span>
                        </div>
                        <div class="col-12" style="width: 160px;">水费
                            <span>{php echo sprintf('%.2f',$water_price);}{$setting['currency']}</span>
                        </div>
                        <div class="col-12" style="width: 160px;">电费
                            <span>{php echo sprintf('%.2f',$power_price);}{$setting['currency']}</span>
                        </div>
                        <div class="col-12" style="width: 160px;">租金
                            <span>{php echo sprintf('%.2f',$rent_price);}{$setting['currency']}</span>
                        </div>
                        <div class="col-12" style="width: 160px;">其他费用
                            <span>{php echo sprintf('%.2f',$orther_price);}{$setting['currency']}</span>
                        </div>
                        <div class="col-12" style="width: 160px;">利润
                            <span style="color: #f00;">{$profit}{$setting['currency']}</span></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <form class="form-horizontal" action="" method="post" onkeydown="if(event.keyCode == 13) return false;">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-hover table-bordered table-text-center">
                        <thead class="navbar-inner">
                        <tr>
                            <th width="300">姓名</th>
                            <th>分红比例</th>
                            <th>分红</th>
                        </tr>
                        </thead>
                        <tbody>
                        {loop $list $row}
                        <tr>
                            <th>{$row['username']}</th>
                            <td>{php echo sprintf('%.2f', $row['fee_rate']);} {$setting['currency']}</td>
                            <td>
                                {php $fee =  $profit * $row['fee_rate'] / 100}
                                {php echo sprintf('%.2f', $fee);}
                                {$setting['currency']}

                            </td>


                            <!--<td>-->
                            <!--<a href="#" class="btn btn-success" target="_blank">详情</a>-->
                            <!--</td>-->
                        </tr>
                        {/loop}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </form>
</div>



{elseif $operation == 'list'}
<div class="main">
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
        <form action="" method="post" class="form-horizontal form" >
            <input type="hidden" name="storeid" value="{$storeid}" />
            <table class="table table-hover">
                <thead class="navbar-inner">
                <tr>
                    <th style="width:20%;">日期</th>
                    <th style="width:15%;">水费</th>
                    <th style="width:15%;">电费</th>
                    <th style="width:15%;">租金</th>
                    <th style="width:15%;">其他</th>
                    <th style="width:20%;text-align:right;">操作</th>
                </tr>
                </thead>
                <tbody id="level-list">
                {loop $list $row}
                <tr>
                    <td>{php echo date("Y-m-d", $row['dateline'])}</td>
                    <td>{$row['water']}</td>
                    <td>{$row['power']}</td>
                    <td>{$row['rent']}</td>
                    <td>{$row['orther']}</td>
                    <td style="text-align:right;">
                        <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('cost', array('op' => 'post', 'id' => $row['id'], 'storeid' => $storeid))}" title="编辑">改</a>
                        <a class="btn btn-default btn-sm" onclick="return confirm('确认删除吗？');return false;"
                           href="{php echo $this->createWebUrl('cost', array('id' => $row['id'], 'op' => 'delete', 'storeid' => $storeid))}" title="删除">删</a>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </form>
        {$pager}
        </div>
    </div>
</div>
{elseif $operation == 'post'}
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
        <input type="hidden" name="storeid" value="{$storeid}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                添加数据
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">水费</label>
                    <div class="col-sm-10 col-lg-9">
                        <div class="input-group">
                            <input type="number" step="0.01" class="form-control" value="{$item['water']}" name="water">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">电费</label>
                    <div class="col-sm-10 col-lg-9">
                        <div class="input-group">
                            <input type="number" step="0.01" class="form-control" value="{$item['power']}" name="power">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">租金</label>
                    <div class="col-sm-10 col-lg-9">
                        <div class="input-group">
                            <input type="number" step="0.01" class="form-control" value="{$item['rent']}" name="rent">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">其他</label>
                    <div class="col-sm-10 col-lg-9">
                        <div class="input-group">
                            <input type="number" step="0.01" class="form-control" value="{$item['orther']}" name="orther">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">日期</label>
                    <div class="col-sm-10 col-lg-9">
                        {php echo tpl_form_field_date('dateline', TIMESTAMP, false);}
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="保存设置" class="btn btn-primary col-lg-3" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
    </form>
</div>
{/if}
{if $_W['isfounder']}
{template 'common/footer'}
{else}
{template 'public/footer'}
{/if}